package com.zr.service.finance.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zr.dao.finance.FinanceInvoiceDao;
import com.zr.dao.finance.FinanceStatementDao;
import com.zr.service.finance.FinanceInvoiceService;
import com.zr.vo.finance.FinanceInvoice;
import com.zr.vo.finance.FinanceStatement;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

@Service
public class FinanceInvoiceServiceImpl implements FinanceInvoiceService {

    //发票dao层
    @Resource
    private FinanceInvoiceDao financeInvoiceDao;

    //对账单dao
    @Resource
    private FinanceStatementDao financeStatementDao;

    /**
     * @author wanglu
     * 查询发票列表
     * @param financeInvoice
     * @return
     */
    @Override
    public PageInfo<FinanceInvoice> getList(FinanceInvoice financeInvoice) {
        PageHelper.startPage(financeInvoice.getPageNum(),financeInvoice.getPageSize());
        return new PageInfo<FinanceInvoice>(financeInvoiceDao.getList(financeInvoice));
    }

    /**
     * @author wanglu
     * 新增发票
     * @param financeInvoice
     * @return
     */
    @Override
    public int add(FinanceInvoice financeInvoice) {
        //对账单表插入发票ID，设置状态
        for (FinanceStatement s: financeInvoice.getStatements()) {
             financeStatementDao.updateInvoiceId(financeInvoice.getInvoiceId(),s.getStatementId());
        }
        return financeInvoiceDao.insertSelective(financeInvoice);
    }
}
